Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ContentSwitcher): add icon-only ContentSwitcher #13378

Merged

Conversation

tw15egan
Copy link
Collaborator

@tw15egan tw15egan commented Mar 20, 2023

Closes #12811

Adds in a new icon-only ContentSwitcher

Changelog

New

  • IconSwitch component was created, and rendered as a child of ContentSwitcher. When this is used instead of Switch, it will render an IconButton.
<ContentSwitcher>
    <IconSwitch name="one" text="Table of Contents">
      <TableOfContents />
    </IconSwitch>
    <IconSwitch name="two" text="Workspace Test">
      <Workspace />
    </IconSwitch>
    <IconSwitch name="three" text="View Mode">
      <ViewMode_2 />
    </IconSwitch>
  </ContentSwitcher>
  • The name passed into IconSwitch will render the Tooltip text. This will also set the aria-label on the IconButton
  • Tests and snapshots added for the new IconSwitch
  • Styles for the new icon-only ContentSwitcher

Changed

  • ContentSwitcher now passes along size to its children.
  • Updated the size prop types to valid v11 sizes.
  • Adjusted styles for the new icon-only ContentSwitcher
  • Added a wrapperClasses prop to IconButton. I needed a way to surface selected + disabled states to the outermost wrapper, and adding one in IconSwitch was causing the role="tab" be too far removed from its parent, and causing screenreader issues (Each button read Tab 1 of 1). Since it is now just 1 level removed, the screen reader announces the number of tabs correctly.

Removed

  • Removed the with layer snapshot and replaced it with the new icon-only story. The with layer story has no visual differences from the default story.

Testing / Reviewing

Go to ContentSwitcher and check out the icon-only story.

  • Ensure it matches the spec, and tooltips appear.
  • Ensure sizes are able to change, and supports both selection modes.
  • Try disabling an icon button and ensure it works.

Make sure there are no regressions to the standard ContentSwitcher

@netlify
Copy link

netlify bot commented Mar 20, 2023

Deploy Preview for carbon-components-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9677d47
🔍 Latest deploy log https://app.netlify.com/sites/carbon-components-react/deploys/643423da437d9e0008da920a
😎 Deploy Preview https://deploy-preview-13378--carbon-components-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Mar 20, 2023

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 9677d47
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/643423da38bd960008f2b891
😎 Deploy Preview https://deploy-preview-13378--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@tw15egan tw15egan force-pushed the icon-only-content-switcher branch 2 times, most recently from 1a69cd7 to 2d326fe Compare March 22, 2023 16:14
@tw15egan tw15egan force-pushed the icon-only-content-switcher branch 3 times, most recently from c458e3f to 9ac8e18 Compare March 23, 2023 16:32
@tw15egan tw15egan marked this pull request as ready for review March 23, 2023 16:53
@tw15egan tw15egan requested review from a team as code owners March 23, 2023 16:53
@tw15egan tw15egan force-pushed the icon-only-content-switcher branch from aeca559 to 95a9c42 Compare March 23, 2023 18:00
Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 🎉 🏆

@@ -141,9 +140,14 @@ export default class ContentSwitcher extends React.Component {
...other
} = this.props;

const isIconOnly = React.Children.map(children, (child) => {
return child.type.displayName === 'IconSwitch';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to make a note here that this locks the API so consumers can only use IconSwitch. It could prove problematic if someone were to to roll their own IconSwitch component and names it something different. Let's cross that bridge if we come to it though - no need to over optimize for it right now imo

Copy link
Member

@laurenmrice laurenmrice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good!! Just a couple of comments.


  • I noticed there is a slight shadow or gray color bug on the left side of the first section when its selected

1

  • When the last section is selected and has focus, the focus border does not completely overlap the selected color layer on the right side.

2

  • The icon color in the sections that are unselected should be $icon-primary.

  • The Large size content switcher should have 20px icons instead of 16px.

Screen Shot 2023-03-30 at 3 07 09 PM

Copy link
Contributor

@aledavila aledavila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending lauren's style issue

@tw15egan tw15egan force-pushed the icon-only-content-switcher branch 3 times, most recently from d57b8b9 to 8cd5b3d Compare March 31, 2023 11:38
@tw15egan tw15egan requested a review from laurenmrice March 31, 2023 12:08
Copy link
Member

@laurenmrice laurenmrice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good except for the focus state in Safari only. The inset padding becomes inconsistent in some content switcher sections in the different sizes.
Apr-04-2023 17-28-14

@tw15egan tw15egan force-pushed the icon-only-content-switcher branch from 2df73f3 to dbf5359 Compare April 10, 2023 10:26
@tw15egan tw15egan requested a review from laurenmrice April 10, 2023 10:28
Copy link
Member

@laurenmrice laurenmrice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me! Thanks TJ! ✅

@kodiakhq kodiakhq bot merged commit e49be55 into carbon-design-system:main Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Icon content switcher: Make a POC
4 participants